<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="开始时间" prop="company">
        <el-date-picker
          clearable
          v-model="queryParams.beginTime"
          type="datetime"
          default-time="00:00:00"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择带班日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="离开时间" prop="vistior">
        <el-date-picker
          clearable
          v-model="queryParams.endTime"
          type="datetime"
          default-time="00:00:00"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择带班日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- v-hasPermi="['app:vehicles:add']" 新增权限 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-popconfirm
          confirm-button-text="好的"
          cancel-button-text="不用了"
          icon="el-icon-info"
          icon-color="red"
          title="确定删除吗？"
          @confirm="handleDelete"
        >
          <el-button
            v-show="activeName == 'first'"
            type="danger"
            plain
            slot="reference"
            icon="el-icon-delete"
            size="mini"
            v-hasPermi="['app:balstLibrary:remove']"
            >删除</el-button
          >
        </el-popconfirm>
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-tabs v-model="activeName">
      <el-tab-pane label="我发起的" name="first">
        <el-table
          :data="ListVehicles"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="" align="center" prop="flowNo" /> -->
          <el-table-column label="姓名" align="center" prop="names" />
          <el-table-column label="标题" align="center" prop="title" />
          <!-- <el-table-column label="申请人id" align="center" prop="applyUseId" /> -->
          <el-table-column label="证件类型" align="center" prop="cardType">
          </el-table-column>
          <el-table-column
            label="计划开始时间"
            align="center"
            prop="beginTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.beginTime, "{y}-{m}-{d} {h}:{m}:{s}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="计划离开时间"
            align="center"
            prop="endTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d} {h}:{m}:{s}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="事由" align="center" prop="contenct" />
          <el-table-column label="状态" align="center" prop="approStatus">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.approStatus == 1" type="warning"
                >待审</el-tag
              >
              <el-tag v-if="scope.row.approStatus == 2" type="success"
                >通过</el-tag
              >
              <el-tag v-if="scope.row.approStatus == 3" type="danger"
                >驳回</el-tag
              >
              <el-tag v-if="scope.row.approStatus == 4" type="info"
                >撤销</el-tag
              >
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="申请时间"
            align="center"
            prop="createTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column
            label="实际进入时间"
            align="center"
            prop="inTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.inTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="实际离开时间"
            align="center"
            prop="outTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.outTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="附件" align="center" prop="remark"> -->
          <!-- <template slot-scope="scope"> -->
          <!-- <el-button -->
          <!-- size="mini" -->
          <!-- type="text" -->
          <!-- icon="el-icon-view" -->
          <!-- @click="look(scope.row.remake)" -->
          <!-- >查看</el-button -->
          <!-- > -->
          <!-- </template> -->
          <!-- </el-table-column> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="Details(scope.row.flowDetails)"
                >查看详细</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="ListVehiclestotal > 0"
          :total="ListVehiclestotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="待我审核" name="second">
        <el-table :data="listByMyslef">
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="" align="center" prop="flowNo" /> -->
          <el-table-column label="姓名" align="center" prop="names" />
          <el-table-column label="标题" align="center" prop="title" />
          <!-- <el-table-column label="申请人id" align="center" prop="applyUseId" /> -->
          <el-table-column label="证件类型" align="center" prop="cardType" />
          <el-table-column
            label="计划开始时间"
            align="center"
            prop="beginTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.beginTime, "{y}-{m}-{d} {h}:{m}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="计划离开时间"
            align="center"
            prop="endTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.endTime, "{y}-{m}-{d} {h}:{m}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="事由" align="center" prop="contenct" />
          <el-table-column
            label="申请时间"
            align="center"
            prop="createTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{m}:{s}") }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="实际进入时间"
            align="center"
            prop="inTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.inTime, "{y}-{m}-{d} {h}:{m}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="实际离开时间"
            align="center"
            prop="outTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.outTime, "{y}-{m}-{d} {h}:{m}:{s}")
              }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="附件" align="center" prop="remark" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="myDetails(scope.row)"
                >去审核</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="listByMysleftotal > 0"
          :total="listByMysleftotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="已通过" name="third">
        <el-table :data="FlowList">
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="" align="center" prop="flowNo" /> -->
          <el-table-column label="姓名" align="center" prop="names" />
          <el-table-column label="标题" align="center" prop="title" />
          <!-- <el-table-column label="申请人id" align="center" prop="applyUseId" /> -->
          <el-table-column label="证件类型" align="center" prop="cardType" />
          <el-table-column
            label="计划开始时间"
            align="center"
            prop="beginTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.beginTime, "{y}-{m}-{d} {h}:{m}:{s}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="计划离开时间"
            align="center"
            prop="endTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d} {h}:{m}:{s}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="事由" align="center" prop="contenct" />
          <el-table-column
            label="申请时间"
            align="center"
            prop="createTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{m}:{s}") }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="实际进入时间"
            align="center"
            prop="inTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.inTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="实际离开时间"
            align="center"
            prop="outTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.outTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="附件" align="center" prop="remark" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="Details(scope.row.flowDetails)"
                >查看详细</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="FlowListtotal > 0"
          :total="FlowListtotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
    </el-tabs>

    <!-- 添加 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="700px"
      append-to-body
      @close="openClose"
    >
    <div class="top">
        <el-steps :space="200" :active="stepIndex" finish-status="success">
          <el-step title="数据录入"></el-step>
          <el-step title="选择审批人"></el-step>
          <el-step title="部门领导审批"></el-step>
          <el-step title="高层领导审批"></el-step>
          <el-step title="发起审核"></el-step>
        </el-steps>
      </div>
      <div class="contentForm" v-if="stepIndex == 0">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-form-item label="标题" prop="title">
            <el-input v-model="form.title" placeholder="请输入标题" />
          </el-form-item>
          <!-- <el-form-item label="姓名" prop="names"> -->
          <!-- <el-input v-model="form.names" placeholder="请输入姓名" /> -->
          <!-- </el-form-item> -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="部门" prop="names">
                <el-cascader
                  placeholder="选择部门后选择人员"
                  :options="deptOptions"
                  :props="{ value: 'id' }"
                  @change="cascaderChange"
                  filterable
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="人员">
                <el-select
                  v-model="form.names"
                  multiple
                  collapse-tags
                  filterable
                >
                  <el-option
                    v-for="item in userSelectList"
                    :key="item.userId"
                    :label="item.nickName"
                    :value="item.nickName"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="计划开始时间" prop="beginTime">
                <el-date-picker
                  clearable
                  v-model="form.beginTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  default-time="00:00:00"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划离开时间" prop="endTime">
                <el-date-picker
                  clearable
                  v-model="form.endTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  default-time="00:00:00"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="证件类型" prop="cardType">
                <el-select v-model="form.cardType" placeholder="请选择">
                  <el-option label="身份证" value="身份证"></el-option>
                  <el-option label="护照" value="护照"></el-option>
                  <el-option label="工作证" value="工作证"></el-option>
                  <el-option label="执行公务证" value="执行公务证"></el-option>
                  <el-option label="其他" value="其他"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="证件"
                prop="contenct"
                v-if="form.cardType == '其他'"
              >
                <el-input v-model="card" placeholder="请输入证件类型" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="事由" prop="contenct">
            <el-input
              v-model="form.contenct"
              placeholder="请输入事由"
              type="textarea"
            />
          </el-form-item>

          <!-- <el-form-item label="附件" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入附件" />
        </el-form-item> -->
        </el-form>
      </div>
      <div class="contentForm" v-if="stepIndex == 1">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>审批人</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex == 2">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>领导审批</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex == 3">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>高层领导审批</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex == 4">
        <el-divider>人员入库信息</el-divider>
        <el-descriptions>
          <el-descriptions-item label="人员">
            <span v-for="(item, index) in form.names" :key="index">{{
              item + "."
            }}</span>
          </el-descriptions-item>
          <el-descriptions-item label="证件类型">{{
            form.cardType
          }}</el-descriptions-item>
          <el-descriptions-item label="计划开始时间">{{
            form.beginTime
          }}</el-descriptions-item>
          <el-descriptions-item label="计划离开时间">{{
            form.endTime
          }}</el-descriptions-item>
          <el-descriptions-item label="事由">{{
            form.contenct
          }}</el-descriptions-item>
        </el-descriptions>
        <el-divider>审批人</el-divider>
        <span v-for="item in checkUserList" :key="item.userId"
          >{{ item.nickName
          }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
        ></span>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="stepIndex != 0" @click="beforTip"
          >上一步</el-button
        >
        <el-button type="primary" v-if="stepIndex != 4" @click="nextTip"
          >下一步</el-button
        >
        <el-button type="primary" v-else @click="submit">提交审核</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情弹出框 -->
    <el-dialog
      title="详情"
      :visible.sync="detailOpen"
      width="1100px"
      append-to-body
    >
      <el-table :data="ditailList">
        <el-table-column label="审核人" align="center" prop="name" />
        <el-table-column label="审核顺序" align="center" prop="sort" />
        <el-table-column label="审核状态" align="center" prop="status">
          <template slot-scope="scope">
            {{ myStatus[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column label="审核意见" align="center" prop="content">
        </el-table-column>
        <el-table-column label="审核时间" align="center" prop="auditTime" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="签名" align="center" prop="sign">
          <template slot-scope="scope">
            <!-- {{scope.row.sign}} -->
            <img
              v-if="scope.row.sign"
              style="display: block; width: 80px; height: 40px"
              :src="scope.row.sign"
            />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 待我审核弹出框 -->
    <el-dialog :visible.sync="mydetailOpen" width="700px" append-to-body>
      <el-divider>审批信息</el-divider>
      <el-descriptions>
        <el-descriptions-item label="入库人员">
          {{ lodingData.names }}
        </el-descriptions-item>
        <el-descriptions-item label="证件类型">{{
          lodingData.cardType
        }}</el-descriptions-item>
        <el-descriptions-item label="预计入库时间">{{
          lodingData.beginTime
        }}</el-descriptions-item>
        <el-descriptions-item label="预计离库时间">{{
          lodingData.endTime
        }}</el-descriptions-item>
        <el-descriptions-item label="事由">{{
          lodingData.contenct
        }}</el-descriptions-item>
      </el-descriptions>
      <el-divider></el-divider>
      <el-form ref="form" :model="myForm" :rules="myRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核" prop="thing">
              <el-switch
                v-model="myForm.status"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="3"
                :inactive-value="4"
                active-text="同意"
                inactive-text="不同意"
              >
              </el-switch>

              <!-- <el-select v-model="myForm.status" placeholder="请选择">
                  <el-option label="通过" :value="3" />
                  <el-option label="不通过" :value="4" />
                </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签名" prop="thing">
              <!-- <el-input v-model="form.thing" placeholder="请输入事由" /> -->
              <!-- <el-button @click="sign()">签字</el-button> -->
              <div
                @click="signLog = true"
                style="width: 200px; background-color: #d9d9d9"
              >
                <el-image
                  :src="signinimg"
                  style="
                    width: 200px;
                    height: 100px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: #999;
                  "
                >
                  <div slot="error">点击签名</div>
                </el-image>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="审核意见" prop="thing"
              ><el-input v-model="myForm.content" placeholder="请输入意见"
            /></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="mySunbit()">提交</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 批准出矿弹出框 -->
    <el-dialog :visible.sync="outOpen" width="700px" append-to-body>
      <el-divider>离场审批</el-divider>
      <el-form ref="form" :model="outForm" :rules="outRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="离场审批" prop="thing">
              <el-select v-model="outForm.flag" placeholder="请选择">
                <el-option label="同意" :value="1" />
                <el-option label="禁止" :value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="离场时间" prop="thing">
              <el-date-picker
                v-model="outForm.departureTime"
                type="datetime"
                placeholder="选择日期时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                default-time="12:00:00"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="permitOut()">提交</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <el-dialog title="电子签名" :visible.sync="signLog" width="700px">
      <signinDia @setsignin="setsignin" :fileName="'sign'"></signinDia>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  addBalstLibrary,
  updateBalstLibrary,
  balstLibraryMy, // 我发起
  balstLibraryLoding, //待审核
  balstLibraryPass, //已经通过
  delBalstLibrary,
} from "@/api/app/balstLibrary";
import { deptTreeSelect, listUser } from "@/api/system/user";
//import { listUser } from "@/api/system/user";
import cache from "@/plugins/cache";
import signinDia from "@/components/signFont/index.vue";
export default {
  components: {
    signinDia,
  },
  name: "Vehicles",
  data() {
    return {
      stepIndex: 0,
      userId: cache.session.getJSON("userId"),
      ListVehicles: [],
      listByMyslef: [],
      FlowList: [],
      activeName: "first",
      deptOptions: [],
      userSelectList: [],
      card: "",
      myStatus: {
        1: "审核中",
        2: "待我审核",
        3: "通过",
        4: "驳回",
      },
      detailStatus: {
        // 1: "待审核",
        3: "通过",
        4: "驳回",
        // 4: "撤销",
      },

      defaultProps: {
        children: "children",
        label: "label",
      },
      // 部门名称
      deptName: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      ListVehiclestotal: 0,
      listByMysleftotal: 0,
      FlowListtotal: 0,
      // 外来车辆管理表格数据
      // vehiclesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      detailOpen: false,
      mydetailOpen: false,
      lodingData: {},
      outOpen: false,
      mydetailData: {},
      ditailList: [],
      // 是否离场时间范围
      daterangeTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginTime: null,
        endTime:null,
        names: null,
      },
      // 表单参数
      form: {
        //approStatus: 1, //审核状态
        //createBy: null,
        //createTime: "2023-12-08 14:21:51", //申请时间
        //flowNo: 1, //审批编号
        //remark: null, //备注
        //title: "", //标题
      },
      myForm: {
        flowNo: null,
        status: 3,
        auditUserId: null,
        sign: null,
        id: null,
        content: "",
      },
      outForm: {
        flowNo: null,
        flag: 1,
        departureTime: null,
      },
      // 表单校验
      rules: {},
      myRules: {},
      outRules: {},
      //人员数据
      userList: [],

      checkUserList: [],
      userPage: {
        pageNum: 1,
        pageSize: 24,
        deptId: null,
        userName: "",
      },
      signinimg: null,
      signLog: false,
      flowNos: null,
    };
  },
  created() {
    this.getList();
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    handleDelete() {
      if (this.flowNos != null && this.flowNos != "") {
        delBalstLibrary(this.flowNos).then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.$modal.msgSuccess("删除成功");
            this.getList()
          }
        });
      } else {
        this.$message.error("未选择删除项");
      }
    },
    handleSelectionChange(val) {
      console.log(val);
      let flowNos = val.map((item) => {
        return item.flowNo;
      });
      this.flowNos = flowNos.join();
    },
    /** 查询外来车辆管理列表 */
    getList() {
      this.getListVehicles();
      this.getListByMyslef();
      this.getFlowList();
    },
    setsignin(img) {
      this.signinimg = img;
      this.signLog = false;
      this.myForm.sign = img;
    },
    // 查看来访详细
    Details(data) {
      console.log(data);
      this.detailOpen = true;
      this.ditailList = data;
    },
    //待我审核详细
    myDetails(data) {
      console.log(data);

      this.myForm.flowNo = data.flowNo;
      this.myForm.id = data.id;
      this.mydetailOpen = true;
      this.lodingData = data;
    },
    // 批准出矿
    out(flowNo) {
      this.outOpen = true;
      this.outForm.flowNo = flowNo;
    },
    // 添加框关闭
    openClose() {
      this.checkUserList = [];
      this.stepIndex = 0;
      this.reset();
    },

    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 查询人员
    userSearch() {
      listUser(this.userPage).then((res) => {
        this.userPage.deptId = null;
        // this.userPage.pageNum = 1;
        if (res.code == 200) {
          this.userList = res.rows;
          this.total = res.total;
        }
      });
    },
    // 人员上一页
    userFooterbefor() {
      if (this.userPage.pageNum >= 2) {
        console.log(this.userPage.pageNum);
        this.userPage.pageNum--;
        console.log(this.userPage.pageNum);
        this.userSearch();
      } else {
        this.$message("已经是第一页了");
      }
    },
    // 人员下一页

    userFooternext() {
      if (this.userPage.pageNum < Math.ceil(this.total / 12)) {
        this.userPage.pageNum++;
        console.log(this.userPage.pageNum);
        this.userSearch();
      } else {
        this.$message("已经是最后一页了");
      }
    },

    cascaderChange(data) {
      console.log(data);
      // pageNum=1&pageSize=6&peopleType=1&deptId=105
      listUser({
        deptId: data[data.length - 1],
        pageNum: 1,
        pageSize: 999,
        peopleType: 1,
      }).then((res) => {
        this.userSelectList = res.rows;
      });
    },

    //添加审批人
    addUser(item) {
      if (
        JSON.stringify(this.checkUserList).indexOf(JSON.stringify(item)) === -1
      ) {
        this.checkUserList.push(item);
      } else {
        this.$message.error("该审批人已经存在");
      }
    },
    // 删除审批用户
    userClose(id) {
      this.checkUserList.some((item, i) => {
        if (item.userId === id) {
          this.checkUserList.splice(i, 1);
        }
      });
    },
    // 提交审批
    submit() {
      // this.reset();
      let data = { ...this.form };
      data.userId = this.userId;
      data.approStatus = 1;
      data.type = 2;
      data.names = data.names.join();

      if (data.cardType == "") {
        data.cardType = this.card;
      }
      data.flowDetails = [];
      this.checkUserList.forEach((item, index) => {
        data.flowDetails.push({ auditUserId: item.userId, sort: index + 1 });
      });

      addBalstLibrary(data).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("提交成功");
          this.open = false;
          this.reset();
          this.stepIndex = 0;
          this.checkUserList = [];
          this.getList();
        } else {
          this.open = false;
          this.reset();
          this.stepIndex = 0;
          this.checkUserList = [];
          this.getList();
          this.$message.error("提交失败");
        }
      });
    },
    // 我的审核
    mySunbit() {
      this.myForm.auditUserId = this.userId;
      updateBalstLibrary(this.myForm).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("审批完成");
        } else {
          this.$message.error("失败");
        }
        this.mydetailOpen = false;
        this.getList();
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.userPage.deptId = data.id;

      this.userPage.pageNum = 1;

      this.userSearch();
    },

    // 我发起的
    async getListVehicles() {
      await balstLibraryMy({
        ...this.queryParams,
        userId: this.userId,
        type: 2,
      }).then((res) => {
        console.log(res, "我发起的");
        if (res.code == 200) {
          this.ListVehicles = res.rows;
          this.ListVehiclestotal = res.total;
        }
      });
    },

    //待审核
    async getListByMyslef() {
      await balstLibraryLoding({
        ...this.queryParams,
        userId: this.userId,
      }).then((res) => {
        console.log(res, "待审核的");
        if (res.code == 200) {
          this.listByMyslef = res.rows;
          this.listByMysleftotal = res.total;
        }
      });
    },
    // 已通过
    async getFlowList() {
      await balstLibraryPass({
        ...this.queryParams,
        approStatus: 2,
        type: 2,
        // userId: this.userId,
      }).then((res) => {
        console.log(res, "已通过的");
        if (res.code == 200) {
          this.FlowList = res.rows;
          this.FlowListtotal = res.total;
        }
      });
    },
    //上一步
    beforTip() {
      this.stepIndex--;
    },
    //下一步
    nextTip() {
      if (this.stepIndex == 0) {
      } else if (this.stepIndex == 4) {
        return;
      }
      this.stepIndex++;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        title: null,
        flowNo: null,
        names: "",
        applyUseId: null,
        cardType: null,
        beginTime: null,
        endTime: null,
        contenct: null,
        createTime: null,
        inTime: null,
        outTime: null,
        remark: null,
        type: 2,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        beginTime: null,
        names: null,
      }),
        this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    // this.ids = selection.map((item) => item.id);
    // this.single = selection.length !== 1;
    // this.multiple = !selection.length;
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getDeptTree();
      this.open = true;
      this.title = "新增炸药库来访人员入库审批";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getVehicles(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改外来车辆管理";
      });
    },
  },
};
</script>
  <style lang='scss' scoped>
.el-tree {
  width: 30%;
}
.topSearch {
  display: flex;
  align-items: center;
}
.userContent {
  display: flex;
}
.userList {
  display: inline-grid;
  grid-template-columns: 100px 100px 100px 100px;
  // grid-template-rows: 50px 50px;
  grid-gap: 5px;
  width: 70%;
  height: 100%;
  span {
    // width: 25%;
    padding: 8px;
    text-align: center;
    background-color: #ccc;
  }
}

.userFooter {
  position: absolute;
  right: 0;
  top: 500px;
  span {
    margin: 20px;
    color: #1890ff;
    cursor: pointer;
  }
}
.spUser {
  display: flex;
  span {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #27aa07;
    color: aliceblue;
    margin: 6px;
    text-align: center;
    line-height: 50px;

    .close {
      position: absolute;
      color: #000;
      top: 0;
      right: -5px;
      font-weight: 700;
      cursor: pointer;
      display: none;
    }
  }
  span:hover .close {
    display: block;
  }
}
</style>